﻿using System.Web.Mvc;
using System.Web.Routing;

namespace SalePromotion.Extensions
{
    public static class UrlExtensions
    {
        public static string PagedUrl<T>(this HtmlHelper<T> helper, int pageNumber)
        {
            var routing = new RouteValueDictionary(helper.ViewContext.RouteData.Values);
            
            // Include query string parameters
            helper.ViewContext.HttpContext.Request.QueryString.CopyTo(routing);            
            
            // Set the page number
            routing["page"] = pageNumber;

            // Create a url for the current page, with the new page number overridden
            return new UrlHelper(helper.ViewContext.RequestContext).RouteUrl(routing);
        }
    }
}